<template>
  <div id="app">
    <h1>根组件</h1>
    <p>{{$store.state.msg}}</p>
    <input type="text" :value="num" @input="hInput" />
    <add-item></add-item>
    <hr />
    <sub-item></sub-item>
    <hr />
    <button @click="resetNum">重置</button>
  </div>
</template>

<script>
import AddItem from "./components/AddItem.vue";
import SubItem from "./components/SubItem.vue";
import { mapMutations, mapState } from "vuex";

export default {
  name: "app",
  data() {
    return {};
  },
  methods: {
    //  hInput (e) {
    //   this.$store.commit('numUpDate', e.target.value)
    // },
    hInput(e) {
      console.log(e.target.value);
     this.updateNum(e.target.value);
    },
    ...mapMutations(["updateNum", "resetNum"]),
  },
  components: {
    AddItem,
    SubItem,
  },
  computed: {
    ...mapState(["num"]),
  },
  mounted(){
    console.log(this.$store.state.msg);
  }
};
</script>

<style>
#app {
  width: 300px;
  margin: 20px auto;
  border: 1px solid #ccc;
  padding: 4px;
}
</style>